package com.android.launcher3;

import java.util.ArrayList;
import java.util.Collections;

import android.app.WallpaperManager;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.database.DataSetObserver;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Camera;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.AsyncTask;
import android.util.AttributeSet;
import android.util.Log;
import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.View;
import android.view.ViewConfiguration;
import android.view.ViewGroup;
import android.view.animation.AccelerateDecelerateInterpolator;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.AnimationUtils;
import android.view.animation.AnticipateInterpolator;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.LayoutAnimationController;
import android.view.animation.LinearInterpolator;
import android.view.animation.OvershootInterpolator;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.Scroller;

public class MenuManager extends ViewGroup implements DragSource, DragScroller,
		DragController.DragListener {
	public final LauncherModel.ApplicationInfoComparator mOrderComparator;
	InterruptableAnimationListener mMenuCloseAnimationListener;
	InterruptableAnimationListener mMenuOpenAnimationListener;
	View mDragView;
	int mDragCell;
	int mDropCell;
	private View.OnClickListener mOnClickListener;
	private View.OnLongClickListener mOnLongClickListener;
	private AnticipateInterpolator mAnticipateInterpolator;
	private ApplicationsAdapter mAdapter = null;
	private ArrayList<ApplicationInfo> mAllAppsList;
	private Bitmap mEditMenuBg;
	private Bitmap mEditTopBg;
	private DragController mDragger;
	private Drawable mPageIndicatorLarge;
	private Drawable mPageIndicatorMiddle;
	private Drawable mPageIndicatorMore;
	private Drawable mPageIndicatorSmall;
	private Interpolator mOpenAlphaAnimationInterpolator;
	private Launcher mLauncher;
	private MenuCloseAnimationController mMenuCloseAni;
	private MenuOpenAnimationController mMenuOpenAni;
	private OvershootInterpolator mOvershootInterpolator;
	private PageIndicator mPageIndicator;
	private Paint mPaint;
	private Rect mDragRect;
	private Runnable mHideIndicator;
	private Scroller mScroller;
	// private Animation mAniFadeIn;
	private Animation[] mAnimationsIn;
	private Animation[] mAnimationsOut;
	private Animation[] mCloseAnimations;
	private Animation[] mOpenAnimations;
	private int[] mPoint;
	private boolean mAnimating;
	private boolean mEnablePageIndicatorShowHide;
	private boolean mFirstLayout = true;
	private boolean mIsClosing;
	private boolean mIsScroll;
	private boolean mIsSingleTap;
	private boolean mLocked;
	private boolean mMultiTouchUsed;
	private boolean mOpenFlag;
	private final boolean mUseLargeDrawablesOnlyForPageIndicator;
	private AdapterDataSetObserver mDataSetObserver;
	private UpdateDBTask mUpdateDBTask;
	private VelocityTracker mVelocityTracker;
	private WallpaperManager mWallpaperManager;
	private float mLastMotionX;
	private float mLastMotionY;
	private float mLastDownX;
	private int SNAP_VELOCITY = 200;
	private final int mColumnNum;
	private Bitmap mDeleteIcon;
	private float mDownX;
	private int mCurrentScreen = -1;
	private int mItemNumOfPage;
	private int mMaximumVelocity;
	private int mMode = 0;
	private int mMovePinch;
	private int mMovePinchStart;
	private int mNextScreen = -1;
	private int mOrientation;
	private int mPageIndicatorGap;
	private int mPageIndicatorLeft;
	private int mPageIndicatorMoreGap;
	private int mPageIndicatorTop;
	private int mRightOffset;
	private int mSnapToScreenDuration;
	private int mTempPage;
	private int mTextSize;
	private int mTopOffset;
	private int mTouchSlop;
	private int mTouchState = TOUCH_STATE_REST;
	private int mTouchedPageIndicatorIndex;
	private long mAnimationStartTime;
	public static final int ANIMATION_IN_TIME = 600;
	public static final int ANIMATION_OUT_TIME = 400;
	public static final int ANIMATION_TIME = 500;
	private static final boolean DEBUG = false;
	private static final boolean DEBUG_TOUCH = false;
	public static final int EDIT_MODE = 2;
	private static final int INVALID_SCREEN = -1;
	public static final int ITEM_ANIMATION_TIME = 300;
	public static final int LAUNCH_MODE_DEFAULT = 0;
	public static final int LAUNCH_MODE_LIST = 1;
	private static final String LOG_TAG = "Launcher.MenuManager";
	private static final boolean MENU_PAGE_LOOPING = false;
	private static final boolean SCROLL_DOWN = true;
	private static final int SNAPTOSCREEN_DURATION = 400;
	private static final int SNAPTOSCREEN_DURATION_HORIZONTAL = 600;
	private static final boolean TEST_AUTOSCROLL = false;
	private static final int TOUCH_STATE_REST = 0;
	private static final int TOUCH_STATE_SCROLLING = 1;
	private static final String TAG = "MenuManager";
	private static int aninmationType = 0;
	private static int originalAninmationType;

	/**
	 * Creates a new MenuManager object.
	 */
	public MenuManager(final Context context, final AttributeSet attrs) {
		super(context, attrs);
		this.mAllAppsList = new ArrayList<ApplicationInfo>();
		this.mOpenFlag = false;
		this.mAnimating = false;

		this.mPoint = new int[2];
		this.mDragRect = new Rect();
		this.mMultiTouchUsed = false;

		this.mOvershootInterpolator = new OvershootInterpolator(4.0F);

		this.mAnticipateInterpolator = new AnticipateInterpolator(4.0F);
		this.mOrientation = 1;
		this.mSnapToScreenDuration = SNAPTOSCREEN_DURATION;
		this.mColumnNum = LauncherConfig.getColumnNo(context);
		this.mItemNumOfPage = context.getResources().getInteger(
				R.integer.item_num_of_page);
		this.mOnClickListener = new AppMenuOnClickListener();
		this.mOnLongClickListener = new AppMenuOnLongClickListener();

		this.mMenuOpenAni = new MenuOpenAnimationController(context);

		this.mMenuCloseAni = new MenuCloseAnimationController(context);

		this.mMenuOpenAnimationListener = new InterruptableAnimationListener() {
			private boolean mIsEnd;

			public void interrupt() {
				this.mIsEnd = true;
			}

			public void onAnimationEnd(final Animation paramAnimation) {
				if (this.mIsEnd) {
					return;
				}

				MenuManager.this.setClipChildren(true);

				int i = MenuManager.this.getChildCount();
				int j = 0;

				while (j < i) {
					MenuManager.this.getChildAt(j).setVisibility(View.VISIBLE);
					j++;
				}

				MenuManager.this.mLauncher.getWorkspace().setVisibility(
						View.INVISIBLE);
				MenuManager.this.unlock();
				this.mIsEnd = true;
			}

			public void onAnimationRepeat(final Animation paramAnimation) {
			}

			public void onAnimationStart(final Animation paramAnimation) {
				MenuManager.this.setClipChildren(false);
				// MenuManager localMenuManager = this.this$0;
				// long l1 = SystemClock.uptimeMillis();
				// long l2 = MenuManager.access$1102(localMenuManager, l1);
				MenuManager.this.lock();
				this.mIsEnd = false;
			}
		};

		this.mMenuCloseAnimationListener = new InterruptableAnimationListener() {
			private boolean mIsEnd;

			public void interrupt() {
				this.mIsEnd = true;

				// boolean bool = MenuManager.access$1202(this.this$0, 0);
			}

			public void onAnimationEnd(final Animation paramAnimation) {
				if (this.mIsEnd) {
					return;
				}

				mLauncher.getWorkspace().setShowIndicator();
				MenuManager.this.setClipChildren(true);
				MenuManager.this.unlock();
				this.mIsEnd = true;

				// boolean bool = MenuManager.access$1202(this.this$0, 0);
			}

			public void onAnimationRepeat(final Animation paramAnimation) {
			}

			public void onAnimationStart(final Animation paramAnimation) {
				MenuManager.this.setClipChildren(false);

				MenuManager localMenuManager = MenuManager.this;
				// long l1 = -SystemClock.uptimeMillis();
				// long l2 = MenuManager.access$1102(localMenuManager, l1);
				localMenuManager.lock();
				this.mIsEnd = false;

				// boolean bool = MenuManager.access$1202(this.this$0, 1);
			}
		};

		this.mUseLargeDrawablesOnlyForPageIndicator = LauncherConfig
				.pageIndicator_getUseLargeDrawablesOnly(context);
		this.mOpenAnimations = new Animation[this.mItemNumOfPage];
		this.mCloseAnimations = new Animation[this.mItemNumOfPage];
		this.mOrderComparator = new LauncherModel.ApplicationInfoComparator();
		init();
	}

	/**
	 * 完整.
	 * 
	 * @param source
	 * @param x
	 * @param y
	 * @param xOffset
	 * @param yOffset
	 * @param dragInfo
	 * 
	 * @return
	 */
	public boolean acceptDrop(final DragSource source, final int x,
			final int y, final int xOffset, final int yOffset,
			final Object dragInfo) {
		LogUtils.d(TAG, "acceptDrop");

		return true;
	}

	public void addApps(final ArrayList<ApplicationInfo> apps) {
		int count = apps.size();
		this.mOrderComparator.setMode(this.mMode);

		// Log.e(TAG,"addApps before  count   "+ count);
		// Log.e(TAG,"addApps  before  "+ mAllAppsList.toString());
		for (int i = 0; i < count; i++) {
			ApplicationInfo app = (ApplicationInfo) apps.get(i);
			int m = Collections.binarySearch(mAllAppsList, app,
					this.mOrderComparator);

			if (m < 0) {
				m = -(m + 1);
			} else {
				// Log.e(TAG,"title "+ app.title);
			}

			this.mAllAppsList.add(m, app);
		}

		// Log.e(TAG,"addApps  after "+ mAllAppsList.toString());
		// Log.e(TAG,"addApps after  count   "+ mAllAppsList.size());
		if (this.mAdapter != null) {
			this.mAdapter.notifyDataSetChanged();
		}
	}

	public void addApplication(ApplicationInfo appInfo) {
		if (null != mAllAppsList && null != appInfo) {
			this.mAllAppsList.add(appInfo);
			if (this.mAdapter != null) {
				this.mAdapter.notifyDataSetChanged();
			}
		}
	}

	/**
	 * 随机特效处理
	 */
	private void checkRandomAnimation() {
		if (originalAninmationType == 1) {
			aninmationType = (int) (Math.random() * 4) + 2;
		} else if (originalAninmationType >= 2) {
			// 只有6种动画,排除掉<随机>..
			aninmationType = originalAninmationType - 1;
		}
	}

	/**
	 * 完整.
	 */
	public void animateClose() {

		// Log.e(TAG,"animateClose");

		this.mLauncher.getWorkspace().setVisibility(View.VISIBLE);

		if (!this.mScroller.isFinished()) {
			this.mScroller.abortAnimation();
			computeScroll();

			int i = this.mCurrentScreen;
			int j = getWidth();
			int k = i * j;
			scrollTo(k, 0);
		}

		int m = getChildCount();
		int n = 0;

		while (n < m) {
			getChildAt(n).setVisibility(View.INVISIBLE);
			n++;
		}

		checkRandomAnimation();
		this.mLauncher.getMenuDrawer().startAnimation(
				this.mAnimationsOut[aninmationType]);
		this.mLauncher.getMenuDrawer().setVisibility(View.INVISIBLE);
		this.mLauncher.getMenuDrawer().setBackgroundClose();
		this.mLauncher.getMenuDrawer().setEnabledProgress(false);
		this.mLauncher.getAppShortcutZone().changeApplicationsIcon();
		this.mLauncher.getAppShortcutZone().drawBg(false, true);

		ViewGroup localViewGroup = (ViewGroup) getChildAt(this.mCurrentScreen);

		if (localViewGroup != null) {
			this.mIsClosing = true;
			localViewGroup.setLayoutAnimation(this.mMenuCloseAni);
			localViewGroup
					.setLayoutAnimationListener(this.mMenuCloseAnimationListener);
		}
	}

	/**
	 * 完整.
	 */
	public void animateOpen() {

		// Log.e(TAG,"animateOpen");

		this.mLauncher.getWorkspace().setVisibility(View.INVISIBLE);

		int i = getChildCount();
		int j = 0;

		while (j < i) {
			getChildAt(j).setVisibility(View.VISIBLE);
			j++;
		}

		this.mLauncher.getMenuDrawer().setBackgroundImage();

		checkRandomAnimation();

		this.mLauncher.getMenuDrawer().startAnimation(
				this.mAnimationsIn[aninmationType]);

		this.mLauncher.getMenuDrawer().setVisibility(View.VISIBLE);

		this.mLauncher.getMenuDrawer().setEnabledProgress(true);

		this.mLauncher.getAppShortcutZone().changeApplicationsIcon();

		this.mLauncher.getAppShortcutZone().drawBg(true, true);

		this.mOpenFlag = true;

		ViewGroup localViewGroup = (ViewGroup) getChildAt(this.mCurrentScreen);
		if (localViewGroup != null) {
			localViewGroup.setLayoutAnimation(this.mMenuOpenAni);
			localViewGroup
					.setLayoutAnimationListener(this.mMenuOpenAnimationListener);
		}

	}

	/**
	 * 完整
	 */
	public void close() {
		this.mLauncher.getWorkspace().setVisibility(View.VISIBLE);

		this.mIsClosing = false;
		this.mMenuCloseAnimationListener.interrupt();
		this.mMenuOpenAnimationListener.interrupt();

		int i = getChildCount();
		int j = 0;

		while (j < i) {
			getChildAt(j).setVisibility(View.INVISIBLE);
			j++;
		}

		this.mLauncher.getMenuDrawer().setVisibility(View.INVISIBLE);
		this.mLauncher.getMenuDrawer().setEnabledProgress(false);
		this.mLauncher.getAppShortcutZone().changeApplicationsIcon();
		this.mLauncher.getAppShortcutZone().drawBg(false, false);
		this.mLauncher.getWorkspace().setShowIndicator();
	}

	@Override
	public void computeScroll() {
		// Log.e(TAG,"computeScroll");
		// Log.e(TAG,"computeScroll "+this.mScrollX);
		// Log.e(TAG,"computeScroll"+this.mCurrentScreen);

		if (!((this.mMode == LAUNCH_MODE_LIST) || (isListChild()))) {
			AppMenu child = (AppMenu) this.getChildAt(this.mCurrentScreen);

			if (child != null) {
				child.myLayout(this.mScrollX);
			} else {
				// Log.e(TAG,"this.mCurrentScreen is  NULL");
			}
			child = (AppMenu) this.getChildAt(this.mNextScreen);

			if (child != null) {
				child.myLayout(this.mScrollX);
			} else {
				child = (AppMenu) this.getChildAt(this.mCurrentScreen - 1);
				if (child != null) {
					child.myLayout(this.mScrollX);
				}

				else {
					// Log.e(TAG,"this.mCurrentScreen-1 is  NULL");
				}

				child = (AppMenu) this.getChildAt(this.mCurrentScreen + 1);
				if (child != null) {
					child.myLayout(this.mScrollX);
				} else {
					// Log.e(TAG,"this.mCurrentScreen+1 is  NULL");
				}

			}
		}

		if ((this.mMode == LAUNCH_MODE_LIST) || (isListChild())) {
			if (!this.mScroller.isFinished()) {
				this.mScroller.abortAnimation();
			}
			mNextScreen = INVALID_SCREEN;
			return;
		}

		if (this.mScroller.computeScrollOffset()) {
			this.mScrollX = this.mScroller.getCurrX();
			this.mScrollY = this.mScroller.getCurrY();
			postInvalidate();
			return;
		}

		if (this.mNextScreen != INVALID_SCREEN) {
			mCurrentScreen = Math.max(0,
					Math.min(mNextScreen, getChildCount() - 1));
			mNextScreen = INVALID_SCREEN;
			clearChildrenCache();
			postInvalidate();
//			if ((this.mTouchState != TOUCH_STATE_SCROLLING)
//					&& (this.mPageIndicator != null)) {
//				;
//			}
//			this.mPageIndicator.hide();
		}
	}

	/**
	 * 完整 .
	 * 
	 * @return
	 */
	public ApplicationsAdapter discardMenuEdit() {
		int i = this.mAdapter.getCount();
		int j = 0;

		while (j < i) {
			ApplicationInfo localApplicationInfo = (ApplicationInfo) this.mAdapter
					.getItem(j);
			localApplicationInfo.editTopNum = localApplicationInfo.topNum;
			localApplicationInfo.editPageNum = localApplicationInfo.pageNum;
			localApplicationInfo.editCellNum = localApplicationInfo.cellNum;
			j++;
		}

		return null;
	}

	@Override
	public boolean dispatchUnhandledMove(final View focused, final int direction) {
		if (direction == View.FOCUS_LEFT) {
			if (getCurrentScreen() > 0) {
				snapToScreen(getCurrentScreen() - 1);
				return true;
			}
		} else if (direction == View.FOCUS_RIGHT) {
			if (getCurrentScreen() < (getChildCount() - 1)) {
				snapToScreen(getCurrentScreen() + 1);
				return true;
			}
		}
		return super.dispatchUnhandledMove(focused, direction);
	}

	public boolean getAnimateStatus() {
		return this.mAnimating;
	}

	public int getCurrentScreen() {
		return this.mCurrentScreen;
	}

	/**
	 * 完整.
	 */
	public int getDragAnimationXOffset(final View v) {
		if ((v != null) && (v.getParent() instanceof AppShortcutZone)) {
			return 0;
		} else {
			return this.mScrollX;
		}
	}

	public int getMode() {
		return this.mMode;
	}

	public int getWhichScreen() {
		final int screenWidth = getWidth();
		int whichScreen = (mScrollX) / screenWidth;

		if (this.mCurrentScreen == whichScreen) {
			if (mScrollX % screenWidth > 50) {
				whichScreen++;
			}
		} else {
			if (this.mCurrentScreen == whichScreen + 1) {
				if (mScrollX % screenWidth > screenWidth - 50) {
					whichScreen++;
				}
			}

		}

		if (whichScreen >= this.getChildCount()) {
			whichScreen = this.getChildCount() - 1;
		}

		return whichScreen;
	}

	public boolean isClosing() {
		return this.mIsClosing;
	}

	public boolean isOpened() {
		return this.mLauncher.getMenuDrawer().getVisibility() == View.VISIBLE;
	}

	public void lock() {
		this.mLocked = true;
	}

	/**
	 * 完整.
	 * 
	 * @param position
	 * @param appMenu
	 * 
	 * @return
	 */
	public View makeItemView(final int position, final ViewGroup appMenu) {

		// 贺辉2011年10月27日11:04:40注释
		// Resources localResources = getResources();

		// Configuration localConfiguration = localResources.getConfiguration();
		// int i = -1;
		// int j = localConfiguration.orientation;
		// int k = this.mOrientation;
		//
		// if (j != k) {
		// i = localConfiguration.orientation;
		//
		// int m = this.mOrientation;
		// localConfiguration.orientation = m;
		//
		// DisplayMetrics localDisplayMetrics1 = localResources
		// .getDisplayMetrics();
		// localResources.updateConfiguration(localConfiguration,
		// localDisplayMetrics1);
		// }

		View localView = this.mAdapter.getView(position, null, appMenu);
		localView.setFocusable(true);
		localView.setOnClickListener(this.mOnClickListener);
		localView.setOnLongClickListener(this.mOnLongClickListener);

		// if (i != -1) {
		// DisplayMetrics localDisplayMetrics2 = localResources
		// .getDisplayMetrics();
		// localConfiguration.orientation = i;
		// localResources.updateConfiguration(localConfiguration,
		// localDisplayMetrics2);
		// }

		return localView;
	}

	/**
	 * 完整.
	 */
	public void onDragEnd() {
		LogUtils.d(TAG, "onDragEnd");
	}

	/**
	 * 完整.
	 * 
	 * @param source
	 * @param x
	 * @param y
	 * @param xOffset
	 * @param yOffset
	 * @param dragInfo
	 */
	public void onDragEnter(final DragSource source, final int x, final int y,
			final int xOffset, final int yOffset, final Object dragInfo) {
		LogUtils.d(TAG, "onDragEnter");
	}

	/**
	 * 完整.
	 * 
	 * @param source
	 * @param x
	 * @param y
	 * @param xOffset
	 * @param yOffset
	 * @param dragInfo
	 */
	public void onDragExit(final DragSource source, final int x, final int y,
			final int xOffset, final int yOffset, final Object dragInfo) {
		LogUtils.d(TAG, "onDragExit");
	}

	// DragSource paramDragSource, int paramInt1, int paramInt2, int paramInt3,
	public void onDragOver(final DragSource source, final int x, final int y,
			final int xOffset, final int yOffset, final Object dragInfo) {
		LogUtils.d(TAG, "onDragOver");
		// Log.e(TAG, "onDragOver");
		// Log.e(TAG, "onDragOver  x   "+x+" y  "+y);
		if ((x < 10) || (x > (this.mLauncher.getMenuDrawer().getWidth() - 10))) {
			this.mDragCell = -1;

			// Log.e(TAG, "onDragOver return  1111");
			return;
		}

		// Log.e(TAG, "onDragOver  22");
		int[] arrayOfInt1 = this.mPoint;
		AppShortcutZone localAppShortcutZone1 = this.mLauncher
				.getAppShortcutZone();
		localAppShortcutZone1.getHitRect(this.mDragRect);

		View localView1;

		// Log.e(TAG, localRect1.toShortString()+" ");

		// 如果经过 AppShortcutZone，
		if (this.mDragRect.contains(x, y)) {
			// Log.e(TAG, "Drag Over  AppShortcutZone");
			AppShortcutZone localAppShortcutZone3 = (AppShortcutZone) localAppShortcutZone1;
			int i6 = localAppShortcutZone3.getIndexOfCell(x, y);

			// Log.e(TAG, "onDragOver  AppShortcutZone  getIndexOfCell  "+i6);
			if (i6 != -1) {
				if ((i6 != this.mDragCell) && (this.mDragView != null)) {
					// Log.e(TAG,
					// "this.mDragView.getParent() "+this.mDragView.getParent().getClass().getName());

					// 如果拖动源是 AppShortcutZone
					if (this.mDragView.getParent() instanceof AppShortcutZone) {
						localAppShortcutZone3.changeItem(mDragView, i6);
						localAppShortcutZone3.setEditIndex(i6);
					}
					// 如果拖动源是 主菜单 ICON.
					else {
						MenuManager localMenuManager1 = this;
						localMenuManager1.removeItem(mDragView);

						ApplicationInfo localApplicationInfo1 = (ApplicationInfo) mDragView
								.getTag();
						View localView4 = localAppShortcutZone3
								.makeItemView(localApplicationInfo1);

						int i14 = localAppShortcutZone3.getVisibleChildCount();
						int i15 = localAppShortcutZone3.getColumnCount();

						if (i14 < i15) {
							localAppShortcutZone3.arrangeItem(i6);
						}

						View localView6 = localAppShortcutZone3.addItem(
								localView4, i6);
						localView4.setVisibility(View.INVISIBLE);

						if (localView6.getTag() != null) {
							// 此处是将 从主菜单拖动来的图标和 AppShortcutZone 上的图标进行交换.放在0的位置.
							View localView8 = this.addItem(localView6, 0);
							localView8.setVisibility(View.INVISIBLE);

							int i18 = getDropScreen();
							int i19 = i18;
							AppMenu localAppMenu1 = (AppMenu) this
									.getChildAt(i19);
							localAppMenu1.cellToPoint(0, arrayOfInt1);

							DragController localDragController = this.mDragger;
							int i21 = localView6.getLeft();
							int i22 = localAppShortcutZone3.getLeft();
							float f1 = i21 + i22;
							float f2 = arrayOfInt1[0];
							int i23 = localView6.getTop();
							int i24 = localAppShortcutZone3.getTop();
							float f3 = i23 + i24;
							int i25 = localAppMenu1.getTop();
							int i26 = arrayOfInt1[1];
							float f4 = i25 + i26;
							float f5 = this.mScrollX;
							float f6 = this.mScrollY;
							// localView8.setVisibility(View.VISIBLE);
							// 此处进行动画，进行位置变换.目前是不行的，所以直接写了上面的一行.
							// Toast.makeText(this.mContext, "startAnimation",
							// Toast.LENGTH_SHORT).show();
							localDragController.startAnimation(localView8, f1,
									f2, f3, f4, f5, f6, ITEM_ANIMATION_TIME);
						}

						// 此时的 mDragView 就相当于从 AppShortcutZone 上拖出来的
						this.mDragView = localView4;
						localAppShortcutZone3.setEditIndex(i6);

						// break label224;
						// if ((i6 != -1) || (this.mDragView == null))
						// continue;
						View localView10 = (View) this.mDragView.getParent();
						int i29 = getDropScreen();
						AppMenu localAppMenu3 = (AppMenu) this.getChildAt(i29);

						if (!(localView10 instanceof AppShortcutZone)
								&& (this.mDragView != localAppMenu3)) {
							this.removeItem(mDragView);

							View localView14 = this.addItem(mDragView, i6);
							localView14.setVisibility(View.INVISIBLE);

							int i32 = localAppMenu3.indexOfChild(localView14);
							localAppMenu3.setEditIndex(i32);
							this.mDropCell = i32;
							this.mDragView = localView14;
						}
					}
				}
			} else {
			}

			this.mDragCell = i6;

			// Log.e(TAG, "onDragOver return  2222");
			return;
		}

		// 如果经过 主菜单，
		int i6 = this.getIndexOfCell(x, y);

		// Log.e(TAG, "localMenuManager7 getIndexOfCell " + i6 + " ");
		if (i6 != -1) {
			if ((i6 != this.mDragCell) && (this.mDragView != null)) {
				localView1 = this.mDragView;

				// 如果拖动源是 AppShortcutZone
				if (((View) this.mDragView.getParent() instanceof AppShortcutZone)) {
					AppShortcutZone localAppShortcutZone = (AppShortcutZone) this.mDragView
							.getParent();
					localAppShortcutZone.removeItem(this.mDragView);
				} else {
					// 先将原来的View 删除.
					this.removeItem(localView1);
				}

				// 然后再增加到新的位置上.
				View localView19 = this.addItem(localView1, i6);
				// 是 INVISIBLE, 看不见，但可以占位置。因为拖动的View 可以看见，所以现在是 INVISIBLE.
				localView19.setVisibility(View.INVISIBLE);

				// localView19.setVisibility(View.VISIBLE);
				int i44 = getDropScreen();
				AppMenu localAppMenu7 = (AppMenu) this.getChildAt(i44);
				int i46 = localAppMenu7.indexOfChild(localView19);
				localAppMenu7.setEditIndex(i46);
				this.mDropCell = i46;
				this.mDragView = localView19;
				this.mDragCell = i46;
			}
		}

		// Log.e(TAG, "onDragOver return  3333");
	}

	/**
	 * 完整.
	 */
	public void onDragStart(final View v, final DragSource dragSource,
			final Object info, final int dragAction) {
		LogUtils.d(TAG, "onDragStart");

		// 如果拖动源是 AppShortcutZone
		// 拖动开始的时候.
		if ((dragSource instanceof AppShortcutZone)) {
			AppShortcutZone localAppShortcutZone = (AppShortcutZone) dragSource;
			this.mDragView = v;

			int i = localAppShortcutZone.indexOfChild(v);
			this.mDropCell = i;
			this.mDragCell = i;
			localAppShortcutZone.setEditIndex(i);

			return;
		}
		// 如果是主菜单的ICON.
		else {
			int k = getDropScreen();
			AppMenu localAppMenu = (AppMenu) getChildAt(k);

			if (localAppMenu == null) {
				return;
			}

			this.mDragView = v;

			int m = localAppMenu.indexOfChild(v);
			this.mDropCell = m;
			this.mDragCell = m;
			localAppMenu.setEditIndex(m);
		}
	}

	/**
	 * 不完整 .
	 * 
	 * @param source
	 * @param x
	 * @param y
	 * @param xOffset
	 * @param yOffset
	 * @param dragInfo
	 */
	public void onDrop(final DragSource source, final int x, final int y,
			final int xOffset, final int yOffset, final Object dragInfo) {
		LogUtils.d(TAG, "onDrop");
		// Log.e(TAG, "onDrop");
		AppMenu currentAppMenu1;
		ViewGroup dragViewParent;
		int[] arrayOfInt1;

		// 如果 mDragView为空，则返回，后面主要是操作 mDragView.
		if (this.mDragView == null) {
			// Log.e(TAG, "onDrop return   11 ");
			return;
		}

		// Log.e(TAG, "onDrop");
		AppShortcutZone localAppShortcutZone1 = this.mLauncher
				.getAppShortcutZone();
		localAppShortcutZone1.getHitRect(this.mDragRect);

		int i = getDropScreen();
		currentAppMenu1 = (AppMenu) this.getChildAt(i);
		dragViewParent = (ViewGroup) this.mDragView.getParent();

		if (dragViewParent == null) {
			// Log.e(TAG, "onDrop return   222 ");
			return;
		}

		arrayOfInt1 = new int[2];

		// 如果拖动源是 AppShortcutZone 的话.
		if (dragViewParent instanceof AppShortcutZone) {
			// Log.e(TAG,"");

			// this.mDragger.startAnimation(this.mDragView, x - xOffset,
			// localAppShortcutZone1.getLeft() + this.mDragView.getLeft(),
			// y - yOffset, localAppShortcutZone1.getTop() +
			// this.mDragView.getTop(), 0.0F,
			// 0.0F, ITEM_ANIMATION_TIME);
			this.mDragView.setVisibility(View.VISIBLE);

			// Log.e(TAG, "onDrop return   AppShortcutZone ");
			//
			// printMenuManager();
			//
			// printApplicationsAdapter();

			// Log.e(TAG, "onDrop  end");

			return;
		}

		// int i4 = this.getIndexOfCell(x, y);

		// // 如果拖动源是 AppShortcutZone 上的子项的话,从 AppShortcutZone 上将拖到的View 删除掉.
		// if (localViewGroup1 instanceof AppShortcutZone) {
		// AppShortcutZone localAppShortcutZone3 = (AppShortcutZone)
		// this.mDragView
		// .getParent();
		// localAppShortcutZone3.removeItem(this.mDragView);
		// }
		// // // 如果拖动源是 主菜单的话,从 MenuManager 上将拖到的View 删除掉.
		// else {
		// MenuManager localMenuManager4 = this;
		// localMenuManager4.removeItem(this.mDragView);
		// }

		// 如果拖动到另外一个屏幕上了.
		if (dragViewParent != currentAppMenu1) {
			// Log.e(TAG, "onDrop return   4444 ");

			// if ((i4 == -1) || (this.mDragView == null)) {
			// if (! this.mDragRect.contains(x, y)) {
			//
			// }
			// } else {
			// }
			//
			this.mDragView.setVisibility(View.VISIBLE);
		}
		// 如果拖动到了当前屏幕. 将mDragView 增加到 i4的位置,首先设置为不可见，然后动画 设置为可见.
		else {
			// Log.e(TAG, "11111111111");
			// View localView5 = this.addItem(this.mDragView, i4);
			// int i9 = currentAppMenu1.indexOfChild(localView5);
			// currentAppMenu1.setEditIndex(i9);
			// this.mDragView = localView5;
			currentAppMenu1.cellToPoint(this.mDragView, arrayOfInt1);

			DragController localDragController2 = this.mDragger;
			float f5 = x - xOffset;
			int i11 = currentAppMenu1.getLeft();
			int i12 = arrayOfInt1[0];
			int i13 = i11 + i12;
			int i14 = this.mScrollX;
			float f6 = i13 - i14;
			int i15 = y - yOffset;
			int i16 = this.mScrollY;
			float f7 = i15 + i16;
			int i17 = currentAppMenu1.getTop();
			int i18 = arrayOfInt1[1];
			float f8 = i17 + i18;
			float f9 = this.mScrollX;
			float f10 = this.mScrollY;
			localDragController2.startAnimation(this.mDragView, f5, f6, f7, f8,
					f9, f10, ITEM_ANIMATION_TIME);

			// Log.e(TAG, "onDrop return   555 ");

			// break;
			// label536: MenuManager localMenuManager4 = this;
			// View localView11 = localView2;
			// localMenuManager4.removeItem(localView11);
			//
		}

		// printMenuManager();
		//
		// printApplicationsAdapter();
		//
		// Log.e(TAG, "onDrop  end");
	}

	/**
	 * 暂时不懂，先这样用着，以后有问题再修改. 如拖到操作是失败的，那么将 mDragView 设置为可见的. (non-Javadoc)
	 * 
	 * @see com.android.launcher3.DragSource#onDropCompleted(android.view.View,
	 *      boolean, java.lang.Object)
	 */
	public void onDropCompleted(final View target, final boolean success,
			final Object dragInfo) {
		LogUtils.d(TAG, "onDropCompleted");
		// Log.e(TAG, "onDropCompleted");
		if (success) {
			addBlankPage();
		} else {
			if (this.mDragView != null) {
				this.mDragView.setVisibility(View.VISIBLE);
			}
		}

		this.mDragView = null;
		this.mDragCell = -1;
		this.mDropCell = -1;
	}

	@Override
	public boolean onInterceptTouchEvent(final MotionEvent ev) {
		LogUtils.d(TAG, "onInterceptTouchEvent-start=" + ev.getAction());

		if (mLocked) {
			LogUtils.d(TAG, "onInterceptTouchEvent-end1=true");

			return true;
		}

		if (this.mAnimating) {
			LogUtils.d(TAG, "onInterceptTouchEvent-end2=true");

			return true;
		}

		if (this.mMode == LAUNCH_MODE_LIST) {
			LogUtils.d(TAG, "onInterceptTouchEvent-end3=false");
			return false;
		}

		final int action = ev.getAction();

		if ((action == MotionEvent.ACTION_MOVE)
				&& (mTouchState != TOUCH_STATE_REST)) {
			return true;
		}

		final float x = ev.getX();
		final float y = ev.getY();

		switch (action) {
		case MotionEvent.ACTION_MOVE: {
			final int xDiff = (int) Math.abs(x - mLastMotionX);
			final int yDiff = (int) Math.abs(y - mLastMotionY);

			final int touchSlop = mTouchSlop;
			boolean xMoved = xDiff > touchSlop;
			boolean yMoved = yDiff > touchSlop;

			if (xMoved || yMoved) {
				if (xMoved) {
					mTouchState = TOUCH_STATE_SCROLLING;
					enableChildrenCache(this.mCurrentScreen - 1,
							this.mCurrentScreen + 1);
				}
			}

			break;
		}

		case MotionEvent.ACTION_DOWN: {
			mLastMotionX = x;
			mLastMotionY = y;
			mLastDownX = x;
			mTouchState = mScroller.isFinished() ? TOUCH_STATE_REST
					: TOUCH_STATE_SCROLLING;

			if (this.getScrollX() % this.CHILD_WIDTH == 0) {
				AppMenu.checkRandomAnimation();
			}

			break;
		}

		case MotionEvent.ACTION_CANCEL:
		case MotionEvent.ACTION_UP: {
			clearChildrenCache();
			mTouchState = TOUCH_STATE_REST;

			break;
		}
		}

		LogUtils.d(TAG, "onInterceptTouchEvent-end5="
				+ (mTouchState != TOUCH_STATE_REST));

		return mTouchState != TOUCH_STATE_REST;
	}

	@Override
	public boolean onTouchEvent(final MotionEvent ev) {
		// Log.e(TAG,"onTouchEvent "+ TAG);
		LogUtils.d(TAG, "onTouchEvent=" + ev.getAction());

		if (mLocked) {
			return true;
		}

		// Log.e(TAG, "onTouchEvent");

		if (mVelocityTracker == null) {
			mVelocityTracker = VelocityTracker.obtain();
		}

		mVelocityTracker.addMovement(ev);

		final int action = ev.getAction();
		final float x = ev.getX();

		switch (action) {
		case MotionEvent.ACTION_DOWN:

			/*
			 * If being flinged and user touches, stop the fling. isFinished
			 * will be false if being flinged.
			 */
			if (!mScroller.isFinished()) {
				mScroller.abortAnimation();
			}

			// Remember where the motion event started
			mLastMotionX = x;
			mLastDownX = x;
			break;

		case MotionEvent.ACTION_MOVE:

			if (mTouchState == TOUCH_STATE_SCROLLING) {
				// Scroll to follow the motion event
				final int deltaX = (int) (mLastMotionX - x);

				// Log.e(TAG,"deltaX "+ deltaX);

				if (deltaX < 0) {

					// Log.e(TAG,"deltaX <0");

					if (deltaX + mScrollX > -(getWidth() / 2)) {

						// if(mScrollX -getWidth()/2 >-deltaX)
						// {
						scrollBy(deltaX, 0);
						// }
						// else
						// {
						// scrollBy(-mScrollX, 0);
						// }

					}
				}

				if (deltaX > 0) {
					final int availableToScroll = getChildAt(
							getChildCount() - 1).getRight()
							- mScrollX - getWidth() + getWidth() / 2;

					if (availableToScroll > 0) {
						scrollBy(Math.min(availableToScroll, deltaX), 0);
					}
				}
				mLastMotionX = x;
				// Log.e(TAG, "scrollBy " + Math.max(-mScrollX, deltaX));
				// scrollBy(deltaX, 0);
			}

			break;

		case MotionEvent.ACTION_UP:

			// Log.e(TAG,"ACTION_UP");

			if (mTouchState == TOUCH_STATE_SCROLLING) {

				final VelocityTracker velocityTracker = mVelocityTracker;
				velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);

				int velocityX = (int) velocityTracker.getXVelocity();

				// Log.e(TAG,"velocityX "+velocityX);

				if ((velocityX > SNAP_VELOCITY) && (mCurrentScreen > 0)) {
					// Fling hard enough to move left
					snapToScreen(mCurrentScreen - 1);
				} else if ((velocityX < -SNAP_VELOCITY)
						&& (mCurrentScreen < (getChildCount() - 1))) {
					// Fling hard enough to move right
					snapToScreen(mCurrentScreen + 1);
				} else {
					snapToDestination();
				}

				if (mVelocityTracker != null) {
					mVelocityTracker.recycle();
					mVelocityTracker = null;
				}

				// 贺辉2011年10月25日17:40:52 增加，为了改善滑动灵敏度
				// float d=
				// x-mLastDownX ;
				//
				// if(d>50){
				// snapToScreen(mCurrentScreen - 1);
				// }
				// else
				// {
				// if(d<-50)
				// {
				// snapToScreen(mCurrentScreen + 1);
				// }
				// else
				// {
				// snapToDestination();
				// }
				// }
				// 修改结束

			}

			mTouchState = TOUCH_STATE_REST;

			break;

		case MotionEvent.ACTION_CANCEL:
			mTouchState = TOUCH_STATE_REST;
		}

		return true;
	}

	/**
	 * 完整
	 */
	public void open() {
		this.mIsClosing = false;
		this.mMenuCloseAnimationListener.interrupt();
		this.mMenuOpenAnimationListener.interrupt();

		int i = getChildCount();
		int j = 0;

		while (j < i) {
			getChildAt(j).setVisibility(View.VISIBLE);
			j++;
		}

		this.mLauncher.getMenuDrawer().setBackgroundImage();
		this.mLauncher.getMenuDrawer().setVisibility(View.VISIBLE);
		this.mLauncher.getMenuDrawer().setEnabledProgress(false);
		this.mLauncher.getAppShortcutZone().changeApplicationsIcon();
		this.mOpenFlag = true;
		this.mLauncher.getAppShortcutZone().drawBg(true, false);

		this.mLauncher.getWorkspace().setVisibility(View.INVISIBLE);
	}

	public void removeApps(final ArrayList<ApplicationInfo> apps,
			final boolean notify) {
		for (ApplicationInfo localApplicationInfo : apps) {
			int k = findAppByComponent(this.mAllAppsList, localApplicationInfo);
			if (k >= 0) {
				this.mAllAppsList.remove(k);
				// Log.e(TAG,"   this.mAllAppsList.remove(k);");
			}
		}

		if (notify && this.mAdapter != null) {
			this.mAdapter.notifyDataSetChanged();
		}
	}

	public void scrollLeft() {
		LogUtils.d(TAG, "scrollLeft");

		// 为什么NextScreen 必须是 INVALID_SCREEN？
		if ((this.mNextScreen == INVALID_SCREEN) && (this.mCurrentScreen > 0)
				&& (this.mScroller.isFinished())) {
			snapToScreen(this.mCurrentScreen - 1);
		}
	}

	public void scrollRight() {
		LogUtils.d(TAG, "scrollRight");

		if (this.mNextScreen == INVALID_SCREEN) {
			if ((this.mCurrentScreen < (getChildCount() - 1))
					&& (this.mScroller.isFinished())) {
				snapToScreen(this.mCurrentScreen + 1);
			}
		}
	}

	/**
	 * 完整
	 */
	public void setAdapter(final ApplicationsAdapter adapter) {
		// Log.e(TAG, "MenuManager setAdapter");
		if (this.mAdapter != null) {
			this.mAdapter.unregisterDataSetObserver(this.mDataSetObserver);
		}

		this.mAdapter = adapter;

		if (this.mAdapter != null) {
			this.mDataSetObserver = new AdapterDataSetObserver();
			this.mAdapter.registerDataSetObserver(this.mDataSetObserver);
			this.mAdapter.setNotifyOnChange(false);
			updateMenu();
		}
	}

	public static void setAninmationType(final int aninmationType2) {
		aninmationType = aninmationType2;
		originalAninmationType = aninmationType2;
	}

	/**
	 * 完整.
	 * 
	 * @param apps
	 */
	public void setApps(final ArrayList<ApplicationInfo> apps) {
		this.mAllAppsList.clear();
		addApps(apps);
	}

	public void setCurrentScreen(final int which) {
		this.mCurrentScreen = which;
	}

	public void setDragger(final DragController dragController) {
		this.mDragger = dragController;
	}

	/**
	 * 基本完整.什么时候需要 mAdapter.notifyDataSetChanged()?
	 * 
	 * @param mode
	 */
	public void setMode(final int mode) {
		LogUtils.d(TAG, "setMode=" + mode);

		if (this.mMode != mode) {
			this.mMode = mode;

			if (!this.mScroller.isFinished()) {
				this.mScroller.abortAnimation();
				computeScroll();
			}

			if (mode != EDIT_MODE) {
				((DragLayer) this.mDragger).setDragMenuListener(null);

				// if (this.mAdapter != null) {
				// this.mAdapter.notifyDataSetChanged();
				// }
			} else {
				((DragLayer) this.mDragger).setDragMenuListener(this);

				// updateMenu();
			}

			updateMenu();
			this.mLauncher.saveMenuMode(mode);
		}
	}

	public void snapToScreen(final int which) {
		snapToScreen(which, mSnapToScreenDuration);
	}

	/**
	 * 完整
	 */
	public void startUpdateDB() {
		// Log.e(TAG, "startUpdateDB");
		this.mUpdateDBTask = new UpdateDBTask();
		this.mUpdateDBTask.execute(new ApplicationsAdapter[] { this.mAdapter });
	}

	/**
	 * 完整
	 */
	public void stopUpdateDB() {
		// Log.e(TAG, "stopUpdateDB");
		if (this.mUpdateDBTask != null) {
			if (this.mUpdateDBTask.getStatus() == AsyncTask.Status.RUNNING) {
				this.mUpdateDBTask.cancel(true);
			}
		}
	}

	public void unlock() {
		this.mLocked = false;
	}

	/**
	 * 完整.
	 * 
	 * @param apps
	 */
	public void updateApps(final ArrayList<ApplicationInfo> apps) {
		removeApps(apps, false);
		addApps(apps);
	}

	@Override
	protected void dispatchDraw(final Canvas canvas) {
		LogUtils.d(TAG, "dispatchDraw-start");

		// LogUtils.i(PageIndicator.TAG, "MenuManager-dispatchDraw-start");

		// Log.d(TAG, "dispatchDraw  start");
		int i = getChildCount();

		if (i <= 0) {
			// LogUtils.i(PageIndicator.TAG, "MenuManager-dispatchDraw-end0");
			LogUtils.d(TAG, "dispatchDraw-end1");

			return;
		}

		int i1;

		if ((this.mLauncher.getStateQuickNavigation() < 0)) {
			this.mLauncher.getMenuDrawer().setEnabledProgress(false);

			int j = i - 1;
			int k = getMeasuredWidth();
			int m = j * k;

			// 如果 mCurrentScreen 还没有设置好，那么设置为最后一个 .
			if (this.mCurrentScreen < 0) {
				this.mCurrentScreen = i - 1;
			}

			// // 屏幕数字标示相关.
			// if ((this.mEnablePageIndicatorShowHide) && (this.mOpenFlag)) {
			// if (this.mPageIndicator != null)
			// this.mPageIndicator.show();
			// if (this.mHideIndicator == null) {
			// this.mHideIndicator = new Runnable() {
			// @Override
			// public void run() {
			// mPageIndicator.hide();
			// postInvalidate();
			// }
			// };
			// }
			// this.mOpenFlag = false;
			// postDelayed(this.mHideIndicator, 1000);
			// }
			if (this.mMode != LAUNCH_MODE_LIST) {
				drawPageIndicator(canvas);
			}

			if ((this.mTouchState != TOUCH_STATE_SCROLLING)
					&& (this.mNextScreen == INVALID_SCREEN)) {
				// Log.e(TAG, "dispatchDraw  draw  only  CurrentScreen");
				drawChild(canvas, getChildAt(mCurrentScreen), getDrawingTime());
				// LogUtils.i(PageIndicator.TAG,
				// "MenuManager-dispatchDraw-end1");

				// Log.d(TAG, "dispatchDraw  end");
				LogUtils.d(TAG, "dispatchDraw-end2");

				return;
			}

			long l2 = getDrawingTime();
			long i5 = this.mCurrentScreen - this.mNextScreen;

			if ((this.mNextScreen >= 0) && (this.mNextScreen <= (i - 1))
					&& (Math.abs(i5) == 1)) {
				// Log.e(TAG, "i5 == 1");
				// Log.e(TAG, "dispatchDraw  draw  mCurrentScreen");
				drawChild(canvas, getChildAt(this.mCurrentScreen), l2);
				// Log.e(TAG, "dispatchDraw  draw  mNextScreen");
				drawChild(canvas, getChildAt(this.mNextScreen), l2);

				// Log.d(TAG, "dispatchDraw  end");
			} else {
				// Log.e(TAG, "mCurrentScreen "+mCurrentScreen);
				// Log.e(TAG, "mNextScreen "+mNextScreen);
				// Log.e(TAG, "dispatchDraw  draw  all  Child");
				// Log.d(TAG, "dispatchDraw  end");
				int i7 = 0;

				while (i7 < i) {
					drawChild(canvas, getChildAt(i7), getDrawingTime());
					i7++;
				}
			}
		}

		LogUtils.d(TAG, "dispatchDraw-end3");

		// LogUtils.i(PageIndicator.TAG, "MenuManager-dispatchDraw-end2");
	}

	@Override
	protected void onLayout(final boolean changed, final int l, final int t,
			final int r, final int b) {
		LogUtils.d(TAG, "onLayout");

		// Log.e(TAG, "onLayout");
		int childCount = getChildCount();

		int childLeft = 0;
		int childTop = this.mTopOffset;

		if (this.mMode == 1) {
			childLeft = 0;
			childTop = 0;
		}

		int k = 0;

		while (k < childCount) {
			View localView = getChildAt(k);

			if (localView.getVisibility() != View.GONE) {
				final int childWidth = localView.getMeasuredWidth();

				// Log.e(TAG,"childWidth "+childWidth);

				final int childBottom = localView.getMeasuredHeight()
						- getPaddingBottom();
				localView.layout(childLeft, childTop, childLeft + childWidth,
						childBottom);

				Log.i(AppMenu.DEBUG_TAG, LOG_TAG + "childLayout-l=" + childLeft
						+ ",t=" + childTop + ",r=" + childLeft + childWidth
						+ ",b=" + childBottom);
				childLeft += childWidth;
			}

			k++;
		}

		initPageIndicator();
	}

	protected void onMeasure(int widthMeasureSpec, final int heightMeasureSpec) {
		LogUtils.d(TAG, "onMeasure");
		super.onMeasure(widthMeasureSpec, heightMeasureSpec);
		Log.i(AppMenu.DEBUG_TAG, LOG_TAG + "onMeasure-widthMeasureSpec="
				+ widthMeasureSpec + ",heightMeasureSpec=" + heightMeasureSpec);

		int widthSpecSize = View.MeasureSpec.getSize(widthMeasureSpec);
		int heightSpecSize = View.MeasureSpec.getSize(heightMeasureSpec);
		Log.i(AppMenu.DEBUG_TAG, LOG_TAG + "onMeasure-widthSpecSize="
				+ widthSpecSize + ",heightSpecSize=" + heightSpecSize);

		if (View.MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.EXACTLY) {
			throw new IllegalStateException(
					"Menulayout can only be used in EXACTLY mode.");
		}

		if (this.mMode == 1) {
			int j = this.mRightOffset;
			widthSpecSize -= j;
			widthMeasureSpec = View.MeasureSpec.makeMeasureSpec(widthSpecSize,
					MeasureSpec.EXACTLY);
		}

		if (View.MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.EXACTLY) {
			throw new IllegalStateException(
					"Menulayout can only be used in EXACTLY mode.");
		}

		int childCount = getChildCount();
		Log.i(AppMenu.DEBUG_TAG, LOG_TAG + "onMeasure-childCount=" + childCount);

		int childIndex = 0;

		while (childIndex < childCount) {
			getChildAt(childIndex).measure(widthMeasureSpec, heightMeasureSpec);
			childIndex++;
		}

		if (this.mFirstLayout) {
			int n = this.mCurrentScreen * widthSpecSize;
			scrollTo(n, 0);
		}

		CHILD_WIDTH = widthSpecSize;
		CHILD_HEIGHT = heightSpecSize;

	}

	/**
	 * DOCUMENT ME!
	 * 
	 * @param view
	 * @param index
	 * 
	 * @return
	 */
	View addItem(final View view, final int index) {
		// index 是不可能大于 mItemNumOfPage 的 .
		// Log.e(TAG, "addItem");
		int i = getDropScreen();
		AppMenu localAppMenu = (AppMenu) getChildAt(i);
		int childCount = localAppMenu.getChildCount();
		ApplicationInfo localApplicationInfo1 = (ApplicationInfo) view.getTag();
		int k = this.mAdapter.getPosition(localApplicationInfo1);

		if (k < 0) {
			// Toast.makeText(this.getContext(), "K<0",
			// Toast.LENGTH_SHORT).show();
			ApplicationsAdapter localApplicationsAdapter = this.mAdapter;
			localApplicationInfo1 = copyAdapterInfo(localApplicationsAdapter,
					localApplicationInfo1);

			if (localApplicationInfo1 == null) {
				return null;
			}
		}

		View localView1;
		k = this.mAdapter.getPosition(localApplicationInfo1);
		localView1 = makeItemView(k, localAppMenu);
		localView1.setTag(localApplicationInfo1); // 这个其实在
													// ApplicationsAdapter中已经设置了.
													// index 是不可能大于
													// mItemNumOfPage 的 .则 j 肯定是
													// 小于 mItemNumOfPage
													// 的.那么还是可以增加一个孩子的.

		if (childCount < index) { // 当前的屏幕不是满的，当前的cellIndex 是在后面的空白区域，那么增加到最后面.
									// Log.e(TAG, "addItem2");
			localAppMenu.addView(localView1);
		} else {
			if (childCount == this.mItemNumOfPage) { // 如果当前屏幕已经满了，还要放置一个孩子，那么首先将最后一个孩子移到下一个屏幕。

				View localView2 = localAppMenu
						.getChildAt(this.mItemNumOfPage - 1);
				localAppMenu.removeView(localView2);
				shiftItem(localView2, i + 1);
			}

			i = 0;
			childCount = localAppMenu.getChildCount();

			while (i < childCount && i < this.mItemNumOfPage) {
				ApplicationInfo localApplicationInfo2 = (ApplicationInfo) localAppMenu
						.getChildAt(i).getTag();
				localApplicationInfo2.editTopNum = -1;
				localApplicationInfo2.editPageNum = i;
				localApplicationInfo2.editCellNum = i;
				i++;
			}

			// Log.e(TAG, "addItem3");
			localAppMenu.addView(localView1, index);
		}

		return localView1;
	}

	void clearChildrenCache() {
		int i = getChildCount();
		int j = 0;
		while (j < i) {
			((AppMenu) getChildAt(j)).setChildrenDrawnWithCacheEnabled(false);
			j++;
		}
	}

	void enableChildrenCache(int start, int end) {
		if (start > end) {
			int tmp = start;
			start = end;
			end = tmp;
		}

		if (end > (this.getChildCount() - 1)) {
			return;
		}

		if (start < 0) {
			return;
		}

		for (int i = start; i <= end; i++) {
			AppMenu localAppMenu1 = (AppMenu) getChildAt(i);
			localAppMenu1.setChildrenDrawnWithCacheEnabled(true);
			localAppMenu1.setChildrenDrawingCacheEnabled(true);
		}
	}

	/**
	 * 完整.
	 * 
	 * @return
	 */
	int getDropScreen() {
		if (this.mScroller.isFinished()) {
			return this.mCurrentScreen;
		} else {
			return this.mNextScreen;
		}
	}

	/**
	 * 基本完整.看以后需求.
	 * 
	 * @param x
	 * @param y
	 * 
	 * @return
	 */
	int getIndexOfCell(final int x, final int y) {
		int i = getDropScreen();

		// Log.e(TAG, "getDropScreen  " + i + "");
		AppMenu localAppMenu = (AppMenu) getChildAt(i);
		int j = localAppMenu.getChildWidth();
		int k = localAppMenu.getChildHeight();
		Rect localRect = new Rect();
		localAppMenu.getHitRect(localRect);
		localRect.offset(-i * localAppMenu.getWidth(), 0);

		int r = -1;

		// Log.e(TAG, "localRect  " + localRect.toShortString() + "");
		// Log.e(TAG, "x  " + x + "");
		if (localRect.contains(x, y)) {
			int xx = x / j;
			int yy = y / k;

			if (yy == 4) {
				yy = 3;
			}

			if (xx == 4) {
				xx = 3;
			}

			// Log.e(TAG, "y   " + y + "");
			// Log.e(TAG, "k   " + k + "");
			// Log.e(TAG, "yy  " + yy + "");
			r = (yy * this.mColumnNum) + xx;
		}

		// Log.e(TAG, "getIndexOfCell  " + r + "");
		return r;
	}

	void printAllAppsList() {
		Log.e(TAG, "mAllAppsList############");
		Log.e(TAG, "" + mAllAppsList.toString());
		Log.e(TAG, "############");
	}

	void printApplicationsAdapter() {
		Log.e(TAG, "printApplicationsAdapter");

		int count = this.mAdapter.getCount();

		for (int i = 0; i < count; i++) {
			ApplicationInfo localApplicationInfo = this.mAdapter.getItem(i);
			Log.e(TAG, "printApplicationsAdapter  topNum="
					+ localApplicationInfo.topNum + ",pageNum="
					+ localApplicationInfo.pageNum + ",cellNum="
					+ localApplicationInfo.cellNum + ",title="
					+ localApplicationInfo.title);
		}

		Log.e(TAG, "#######################");

		for (int i = 0; i < count; i++) {
			ApplicationInfo localApplicationInfo = this.mAdapter.getItem(i);
			Log.e(TAG, "printApplicationsAdapter  editTopNum="
					+ localApplicationInfo.editTopNum + ",editPageNum="
					+ localApplicationInfo.editPageNum + ",editCellNum="
					+ localApplicationInfo.editCellNum + ",title="
					+ localApplicationInfo.title);
		}

		Log.e(TAG, "#######################");
	}

	void printMenuManager() {
		Log.e(TAG, "$$$$$$$$$$$$$$$$$$$$");

		int menuCount = this.getChildCount();

		for (int i = 0; i < menuCount; i++) {
			AppMenu localAppMenu = (AppMenu) this.getChildAt(i);
			int appCount = localAppMenu.getChildCount();

			for (int j = 0; j < appCount; j++) {
				Object localObject = localAppMenu.getChildAt(j).getTag();

				if ((localObject instanceof ApplicationInfo)) {
					ApplicationInfo localApplicationInfo = (ApplicationInfo) localObject;
					Log.e(TAG, "printMenuManager  " + i + " " + j + "  topNum="
							+ localApplicationInfo.topNum + ",pageNum="
							+ localApplicationInfo.pageNum + ",cellNum="
							+ localApplicationInfo.cellNum + ",title="
							+ localApplicationInfo.title);
				}
			}
		}

		Log.e(TAG, "$$$$$$$$$$$$$$$$$$$$");
	}

	/**
	 * 完整.
	 * 
	 * @param v
	 */
	void removeItem(final View v) {
		int i = getChildCount();
		AppMenu localAppMenu = (AppMenu) v.getParent();
		int j = 0;

		while (j < i) {
			if (getChildAt(j) == localAppMenu) {
				localAppMenu.removeView(v);
				return;
			} else {
				j++;
			}
		}
	}

	void resume() {
		int i = getChildCount();
		int j = this.mCurrentScreen;

		if (i > 1) {
			if (j < 0) {
				j = i - 1;
				this.mCurrentScreen = j;
			}
		} else {
			this.mCurrentScreen = 0;
		}

		this.mNextScreen = INVALID_SCREEN;

		int k = getWidth();

		if (k != 0) {
			Scroller localScroller = this.mScroller;

			if ((localScroller != null) && (!localScroller.isFinished())) {
				localScroller.abortAnimation();
			}

			int m = j * k;
			scrollTo(m, 0);
		}
	}

	void setLauncher(final Launcher launcher) {
		this.mLauncher = launcher;
	}

	void shiftItem(final View view) {
		int i = getDropScreen();
		shiftItem(view, i);
	}

	/**
	 * 将View 放置在 whichScreen 这个屏幕的第一个位置上， 如果 whichScreen 已经满了，那么递归到下一个屏幕.
	 * 
	 * @param view
	 * @param whichScreen
	 */
	void shiftItem(final View view, final int whichScreen) {
		// Log.e(TAG, "shiftItem paramInt " + whichScreen);
		AppMenu localAppMenu;
		ApplicationInfo localApplicationInfo1;
		int i;

		// 请求的屏幕不够，则增加一个屏幕.
		if (getChildCount() <= whichScreen) {
			localAppMenu = makeMenuView();
		} else {
			localAppMenu = (AppMenu) getChildAt(whichScreen);
		}

		localApplicationInfo1 = (ApplicationInfo) view.getTag();
		i = this.mAdapter.getPosition(localApplicationInfo1);

		// if (i >= 0)
		// break label83;
		if (i < 0) {
			localApplicationInfo1 = copyAdapterInfo(this.mAdapter,
					localApplicationInfo1);
		}

		// if (localApplicationInfo1 != null)
		// break label72;
		i = this.mAdapter.getPosition(localApplicationInfo1);

		View localView1 = makeItemView(i, localAppMenu);
		localView1.setTag(localApplicationInfo1);
		// 增加到第一个的位置.
		localAppMenu.addView(localView1, 0);

		// 如果增加后发现超过最大数目，则将最后一个孩子继续移到下一个屏幕.
		int j = localAppMenu.getChildCount();

		if (j > this.mItemNumOfPage) {
			int m = j - 1;
			View localView2 = localAppMenu.getChildAt(m);
			localAppMenu.removeView(localView2);

			int n = whichScreen + 1;
			shiftItem(localView2, n);
		}

		// 不懂是什么意思.
		int i1 = 0;

		int c = localAppMenu.getChildCount();

		while ((i1 < c) && (i1 < this.mItemNumOfPage)) {
			ApplicationInfo localApplicationInfo2 = (ApplicationInfo) localAppMenu
					.getChildAt(i1).getTag();
			localApplicationInfo2.editTopNum = -1;
			localApplicationInfo2.editPageNum = whichScreen;
			localApplicationInfo2.editCellNum = i1;
			i1++;
		}
	}

	void testAutoScroll() {
		if (getChildCount() <= 1) {
			return;
		}

		int i = this.mCurrentScreen;

		if (i == 0) {
			i = 1;
		}

		while (i >= 0) {
			snapToScreen(i);
			i--;
		}
	}

	private static int findAppByComponent(
			final ArrayList<ApplicationInfo> apps, final ApplicationInfo app) {
		ComponentName localComponentName = app.intent.getComponent();
		int count = apps.size();

		for (int i = 0; i < count; i++) {
			if (((ApplicationInfo) apps.get(i)).intent.getComponent().equals(
					localComponentName)) {
				return i;
			}
		}

		return -1;
	}

	/**
	 * 完整 . 这样做的目的是要始终保持最 后一页是空白的.
	 */
	private void addBlankPage() {
		// Log.e(TAG, "addBlankPage");
		if (this.mMode != EDIT_MODE) {
			return;
		}

		int i = getChildCount();

		if (i == 0) {
			return;
		}

		if (((ViewGroup) getChildAt(i - 1)).getChildCount() == 0) {
			// Log.e(TAG, "addBlankPage return  111");
			return;
		}

		// Log.e(TAG, "addBlankPage return  22222");
		makeMenuView();
	}

	/**
	 * 不明白.
	 * 
	 * @param paramApplicationsAdapter
	 * @param paramApplicationInfo
	 * 
	 * @return
	 */
	private ApplicationInfo copyAdapterInfo(
			final ApplicationsAdapter paramApplicationsAdapter,
			final ApplicationInfo paramApplicationInfo) {
		if ((paramApplicationsAdapter == null)
				|| (paramApplicationInfo == null)) {
			return null;
		}

		ApplicationInfo localApplicationInfo = null;
		int i = paramApplicationsAdapter.getCount();
		int j = 0;

		while (j < i) {
			localApplicationInfo = (ApplicationInfo) this.mAdapter.getItem(j);

			CharSequence localCharSequence1 = localApplicationInfo.title;
			CharSequence localCharSequence2 = paramApplicationInfo.title;

			if (localCharSequence1.equals(localCharSequence2)) {
				String str1 = localApplicationInfo.intent.getComponent()
						.flattenToString();
				String str2 = paramApplicationInfo.intent.getComponent()
						.flattenToString();

				if (str1.equals(str2)) {
					int k = paramApplicationInfo.topNum;
					localApplicationInfo.topNum = k;

					int m = paramApplicationInfo.pageNum;
					localApplicationInfo.pageNum = m;

					int n = paramApplicationInfo.cellNum;
					localApplicationInfo.cellNum = n;

					int i1 = paramApplicationInfo.editTopNum;
					localApplicationInfo.editTopNum = i1;

					int i2 = paramApplicationInfo.editPageNum;
					localApplicationInfo.editPageNum = i2;

					int i3 = paramApplicationInfo.editCellNum;
					localApplicationInfo.editCellNum = i3;

					return localApplicationInfo;
				}
			}

			j++;
		}

		return null;
	}

	private void createListView(final ApplicationsAdapter appAdapter) {
		ArrayList<ApplicationInfo> infoList = new ArrayList<ApplicationInfo>();
		infoList.clear();

		int count = appAdapter.getCount();

		for (int i = 0; i < count; i++) {
			ApplicationInfo info = (ApplicationInfo) appAdapter.getItem(i);

			if (info.topNum == -1) {
				infoList.add(info);
			}
		}

		ApplicationsListAdapter listAdapter = new ApplicationsListAdapter(
				getContext(), infoList);
		listAdapter.sort(new LauncherModel.ApplicationInfoComparator());

		ListView listView = new ListView(getContext());
		listView.setAdapter(listAdapter);

		ViewGroup.LayoutParams localLayoutParams = new ViewGroup.LayoutParams(
				LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);
		this.addView(listView, localLayoutParams);

		ListViewOnItemClickListener onItemClickListener = new ListViewOnItemClickListener();
		ListViewOnItemLongClickListener onItemLongClickListener = new ListViewOnItemLongClickListener();

		listView.setOnItemClickListener(onItemClickListener);
		listView.setOnItemLongClickListener(onItemLongClickListener);
		this.mCurrentScreen = 0;
		this.scrollTo(0, 0);
	}

	final Camera mCamera = new Camera();

	private int CHILD_WIDTH;
	private int CHILD_HEIGHT;

	@Override
	protected boolean drawChild(Canvas canvas, View child, long drawingTime) {
		boolean restore = true;
		float distance = child.getLeft() - this.mScrollX;
		final int start = 6;

		switch (AppMenu.mAninmationType) {
		// 波浪
		case start: {
			float x = 0;
			float y = child.getHeight() / 2;

			if (distance > CHILD_WIDTH || distance < -CHILD_WIDTH) {
				return true;
			}

			if (distance > 0) {
				x = child.getLeft();
			} else {
				x = child.getRight();
			}

			canvas.save();

			Matrix ctm = new Matrix();
			mCamera.save();
			mCamera.getMatrix(ctm);

			float s = ((CHILD_WIDTH - Math.abs(distance)) / CHILD_WIDTH);
			ctm.postScale(s, s, x, y);
			canvas.concat(ctm);
			mCamera.restore();
			break;
		}

			// 翻滚
		case start + 1: {
			float x = child.getLeft() + distance;
			int y = CHILD_HEIGHT - 70;
			float degree = -(distance / CHILD_WIDTH * 2) * 30;
			canvas.save();

			Matrix ctm = new Matrix();
			mCamera.save();
			mCamera.rotateZ(degree);
			mCamera.getMatrix(ctm);
			ctm.preTranslate(-x, -y);
			ctm.postTranslate(x, y);
			canvas.concat(ctm);
			mCamera.restore();
			break;
		}

			// 翻转
		case start + 2: {
			float x = child.getLeft() - distance + CHILD_WIDTH / 2;
			int y = 0;
			float degree = (distance / CHILD_WIDTH * 2) * 90;

			if (degree > 90 || degree < -90) {
				return true;
			}

			canvas.save();

			Matrix ctm = new Matrix();
			mCamera.save();
			mCamera.rotateY(degree);
			mCamera.getMatrix(ctm);
			ctm.preTranslate(-x, -y);
			ctm.postTranslate(x, y);
			canvas.concat(ctm);
			mCamera.restore();
			break;
		}

			// 风车
		case start + 3: {
			int t = -10;
			int x = CHILD_WIDTH / 2;
			Matrix m = canvas.getMatrix();
			float degree = (distance / 1000.0f) * 90;
			canvas.save();

			Matrix ctm = new Matrix();
			mCamera.save();
			mCamera.translate(x, t, 0);
			mCamera.rotateZ(degree);
			mCamera.translate(-x, -t, 0);
			mCamera.getMatrix(ctm);
			m.postConcat(ctm);
			canvas.setMatrix(m);
			mCamera.restore();
			break;
		}

			// 盒子内
		case start + 4: {
			float x = child.getLeft() - distance + CHILD_WIDTH / 2;
			float y = CHILD_HEIGHT / 2;
			float degree;

			if (distance > 0) {
				x = child.getLeft();
			} else {
				x = child.getRight();
			}

			int factor = 50;

			degree = -(distance / CHILD_WIDTH * 2) * factor;

			if (degree > 90 || degree < -90) {
				return true;
			}

			canvas.save();

			Matrix ctm = new Matrix();
			mCamera.save();
			mCamera.translate(0.0f, 0, 0.0f);
			mCamera.rotateY(degree);
			mCamera.getMatrix(ctm);
			ctm.preTranslate(-x, -y);
			ctm.postTranslate(x, y);
			canvas.concat(ctm);
			mCamera.restore();
			break;
		}

			// 盒子外
		case start + 5: {
			float x = child.getLeft() - distance + CHILD_HEIGHT / 2;
			float y = CHILD_HEIGHT / 2;
			float degree;

			if (distance > 0) {
				x = child.getLeft();
			} else {
				x = child.getRight();
			}

			int factor = 50;
			degree = (distance / CHILD_WIDTH * 2.0f) * factor;

			if (degree > 90 || degree < -90) {
				return true;
			}

			canvas.save();

			Matrix ctm = new Matrix();
			mCamera.save();
			mCamera.rotateY(degree);
			mCamera.getMatrix(ctm);
			ctm.preTranslate(-x, -y);
			ctm.postTranslate(x, y);
			canvas.concat(ctm);
			mCamera.restore();
			break;
		}

			// 弹跳
		case start + 6: {
			canvas.save();
			Matrix ctm = new Matrix();
			mCamera.save();
			mCamera.translate(distance * 0.0f, Math.abs(distance) * 0.3f, 0);
			mCamera.getMatrix(ctm);
			canvas.concat(ctm);
			mCamera.restore();
			break;
		}

			// 推压
		case start + 7: {
			float x = 0;
			float y = CHILD_HEIGHT / 2;

			if (distance > 0) {
				x = child.getLeft();
			} else {
				x = child.getRight();
			}

			canvas.save();
			Matrix ctm = new Matrix();
			mCamera.save();
			mCamera.getMatrix(ctm);

			float s = ((CHILD_WIDTH - Math.abs(distance)) / CHILD_WIDTH);
			ctm.postScale(s, 1, x, y);
			canvas.concat(ctm);
			mCamera.restore();
			break;
		}

		default: {
			restore = false;
		}
			break;
		}
		boolean res = super.drawChild(canvas, child, drawingTime);
		if (restore) {
			canvas.restore();
		}
		return res;
	}

	private void drawPageIndicator(final Canvas canvas) {
		// if(true)
		// return;
		// Log.e(TAG,"drawPageIndicator");
		int i = getWhichScreen();

		// LogUtils.i(PageIndicator.TAG,
		// "MenuManager-drawPageIndicator-start-whichScreen=" + i
		// + ", childCount=" + this.getChildCount());

		// Log.e(TAG,"drawPageIndicator  getWhichScreen  "+i);

		final PageIndicator localPageIndicator = this.mPageIndicator;

		if (localPageIndicator == null) {
			return;
		}

		// 在孩子数目小于9个的时候，不显示 左右两边的more 图标.
		if (this.getChildCount() <= 9) {
			localPageIndicator.setCurrentPage(i,
					mUseLargeDrawablesOnlyForPageIndicator);
			localPageIndicator.enableRightMore(false);
			localPageIndicator.enableLeftMore(false);
			localPageIndicator.setFirstTextNum(0);
		} else {
			// 小于中间值的左边
			if (i < 4) {
				localPageIndicator.setCurrentPage(i,
						mUseLargeDrawablesOnlyForPageIndicator);
				localPageIndicator.enableRightMore(true);
				localPageIndicator.enableLeftMore(false);
				localPageIndicator.setFirstTextNum(0);
			} else {
				// 大于中间值的右边 中间值的左边为4,中间值的右边为 (this.getChildCount() -4).
				if (i >= (this.getChildCount() - 4)) {
					localPageIndicator.setCurrentPage(
							(9 + i) - this.getChildCount(),
							mUseLargeDrawablesOnlyForPageIndicator);
					localPageIndicator.enableRightMore(false);
					localPageIndicator.enableLeftMore(true);
					localPageIndicator
							.setFirstTextNum(this.getChildCount() - 9);
				}
				// 在中间的时候
				else {
					localPageIndicator.setCurrentPage(4,
							mUseLargeDrawablesOnlyForPageIndicator);
					localPageIndicator.enableRightMore(true);
					localPageIndicator.enableLeftMore(true);
					localPageIndicator.setFirstTextNum(i - 4);
				}
			}
		}

		int j = this.mPageIndicatorLeft;
		int k = this.mScrollX;
		int m = j + k;
		int n = this.mPageIndicatorTop;
		localPageIndicator.setOffset(m, n);

		if (!localPageIndicator.draw(canvas)) {
			postInvalidate();
		}

		// LogUtils.i(PageIndicator.TAG, "MenuManager-drawPageIndicator-end");
	}

	/**
	 * 完整.
	 * 
	 * @param index
	 * 
	 * @return
	 */
	private AppMenu getEmptyPageView(final int index) {

		// if(index==0)
		// {
		// Log.e(TAG,"0000");
		//
		// }
		// Log.e(TAG,"getEmptyPageView mItemNumOfPage "+mItemNumOfPage);

		int i = getChildCount();

		// Log.e(TAG, "index "+index+" getChildCount  "+ i );

		if (index >= i) {
			AppMenu localAppMenu1 = makeMenuView();
			this.mTempPage = i;
			// Log.e(TAG,"make  the "+i+" screen");
			return localAppMenu1;
		} else {
			int j = ((AppMenu) getChildAt(index)).getChildCount();
			if (j < this.mItemNumOfPage) {
				this.mTempPage = index;
				return (AppMenu) getChildAt(index);
			} else {
				// Log.e(TAG," "+index+" screen  is  full, make  next  screen");
				return getEmptyPageView(index + 1);
			}
		}
	}

	private float getXDeltaValue(final int paramInt) {
		return 10;
	}

	private float getYDeltaValue(final int paramInt) {
		return 10;
	}

	private void init() {
		Resources localResources = getResources();
		setClipChildren(false);
		this.mOrientation = localResources.getConfiguration().orientation;
		this.mScroller = new Scroller(getContext());
		this.mCurrentScreen = 0;
		this.mPaint = new Paint();
		this.mPaint.setDither(false);

		ViewConfiguration localViewConfiguration = ViewConfiguration
				.get(getContext());
		this.mTouchSlop = localViewConfiguration.getScaledTouchSlop();

		this.mMaximumVelocity = localViewConfiguration
				.getScaledMaximumFlingVelocity();

		this.SNAP_VELOCITY = localViewConfiguration
				.getScaledMinimumFlingVelocity() * 6;

		this.SNAP_VELOCITY = 100;

		if (this.mDeleteIcon == null) {
			this.mDeleteIcon = BitmapFactory.decodeResource(localResources,
					R.drawable.homescreen_menu_icon_delete);
		}

		if (this.mEditTopBg == null) {
			this.mEditTopBg = BitmapFactory.decodeResource(localResources,
					R.drawable.homescreen_menu_icon_edit_bg);
		}

		if (this.mEditMenuBg == null) {
			this.mEditMenuBg = this.mEditTopBg;
		}

		this.mPageIndicatorSmall = localResources
				.getDrawable(R.drawable.homescreen_menu_page_focus_small);
		this.mPageIndicatorMiddle = localResources
				.getDrawable(R.drawable.homescreen_menu_page_focus_middle);
		this.mPageIndicatorLarge = localResources
				.getDrawable(R.drawable.homescreen_menu_page_focus_large);
		this.mPageIndicatorMore = localResources
				.getDrawable(R.drawable.homescreen_menu_page_more);
		this.mTopOffset = localResources
				.getDimensionPixelSize(R.dimen.menu_top_offset);
		this.mTextSize = localResources
				.getDimensionPixelSize(R.dimen.pageindicator_fontsize);
		this.mPageIndicatorGap = localResources
				.getDimensionPixelSize(R.dimen.pageindicator_gap);
		this.mPageIndicatorMoreGap = localResources
				.getDimensionPixelSize(R.dimen.pageindicator_moregap);

		int i4 = this.mPageIndicatorSmall.getIntrinsicWidth();
		int i5 = this.mPageIndicatorSmall.getIntrinsicHeight();
		this.mPageIndicatorSmall.setBounds(0, 0, i4, i5);

		int i6 = this.mPageIndicatorMiddle.getIntrinsicWidth();
		int i7 = this.mPageIndicatorMiddle.getIntrinsicHeight();
		this.mPageIndicatorMiddle.setBounds(0, 0, i6, i7);

		int i8 = this.mPageIndicatorLarge.getIntrinsicWidth();
		int i9 = this.mPageIndicatorLarge.getIntrinsicHeight();
		this.mPageIndicatorLarge.setBounds(0, 0, i8, i9);

		int i10 = this.mPageIndicatorMore.getIntrinsicWidth();
		int i11 = this.mPageIndicatorMore.getIntrinsicHeight();
		this.mPageIndicatorMore.setBounds(0, 0, i10, i11);

		this.mEnablePageIndicatorShowHide = localResources
				.getBoolean(R.bool.pageindicator_showhide_enable);

		mAnimationsIn = new Animation[6];

		mAnimationsOut = new Animation[6];

		// 默认
		mAnimationsIn[0] = AnimationUtils.loadAnimation(getContext(),
				R.anim.fade_in_fast);

		mAnimationsOut[0] = AnimationUtils.loadAnimation(getContext(),
				R.anim.fade_out_fast);

		// this.mAniFadeIn= mAnimationsIn[0];
		//
		// this.mAniFadeOut = mAnimationsOut[0] ;

		// 风车
		this.mAnimationsIn[1] = AnimationUtils.loadAnimation(getContext(),
				R.anim.scale_rotate_enter);

		this.mAnimationsOut[1] = AnimationUtils.loadAnimation(getContext(),
				R.anim.scale_rotate_exit);

		// 缩放
		this.mAnimationsIn[2] = AnimationUtils.loadAnimation(getContext(),
				R.anim.scale_enter);

		this.mAnimationsOut[2] = AnimationUtils.loadAnimation(getContext(),
				R.anim.scale_exit);

		// 缩放2
		this.mAnimationsIn[3] = AnimationUtils.loadAnimation(getContext(),
				R.anim.scale_enter_1);

		this.mAnimationsOut[3] = AnimationUtils.loadAnimation(getContext(),
				R.anim.scale_exit_1);

		// 翻转

		// this.mAniFadeIn.setDuration(SNAPTOSCREEN_DURATION_HORIZONTAL);
		// this.mAniFadeOut.setDuration(SNAPTOSCREEN_DURATION);
		AnimationSet enterSet = new AnimationSet(true);

		enterSet.setInterpolator(new AccelerateDecelerateInterpolator());

		Rotate3dAnimation enter = new Rotate3dAnimation(90, 0, 160, 0, 1.0f,
				false);

		enter.setDuration(600);

		enterSet.addAnimation(enter);

		ScaleAnimation enterScale = new ScaleAnimation(0.8f, 1.0f, 0.8f, 1.0f,
				Animation.RELATIVE_TO_PARENT, 0.5f,
				Animation.RELATIVE_TO_PARENT, 0.5f);

		enterScale.setDuration(600);

		enterSet.addAnimation(enterScale);

		this.mAnimationsIn[4] = enterSet;

		AnimationSet exitSet = new AnimationSet(true);

		exitSet.setInterpolator(new AccelerateInterpolator());

		Rotate3dAnimation exit = new Rotate3dAnimation(0, 90, 160, 0, 1.0f,
				false);

		exit.setDuration(600);

		exitSet.addAnimation(exit);

		ScaleAnimation exitScale = new ScaleAnimation(1.0f, 0.80f, 1.0f, 0.8f,
				Animation.RELATIVE_TO_PARENT, 0.5f,
				Animation.RELATIVE_TO_PARENT, 0.5f);
		exitScale.setDuration(600);
		exitSet.addAnimation(exitScale);

		this.mAnimationsOut[4] = exitSet;

		// 电视机
		AnimationSet enterSet5 = new AnimationSet(true);
		enterSet5.setInterpolator(new AccelerateInterpolator());

		ScaleAnimation enterScale5 = new ScaleAnimation(1.05f, 1.0f, 0.90f,
				1.0f, Animation.RELATIVE_TO_PARENT, 0.5f,
				Animation.RELATIVE_TO_PARENT, 0.5f);
		enterScale5.setDuration(600);
		enterSet5.addAnimation(enterScale5);
		this.mAnimationsIn[5] = enterSet5;

		AnimationSet exitSet5 = new AnimationSet(true);
		exitSet5.setInterpolator(new DecelerateInterpolator());

		ScaleAnimation exitScale5 = new ScaleAnimation(1.0f, 1.0f, 0.025f,
				0.0f, Animation.RELATIVE_TO_PARENT, 0.5f,
				Animation.RELATIVE_TO_PARENT, 0.5f);
		exitScale5.setDuration(600);
		exitSet5.addAnimation(exitScale5);
		this.mAnimationsOut[5] = exitSet5;

		if (this.mOrientation == LinearLayout.HORIZONTAL) {
			this.mSnapToScreenDuration = SNAPTOSCREEN_DURATION_HORIZONTAL;
		} else {
			this.mSnapToScreenDuration = SNAPTOSCREEN_DURATION;
		}

		this.mWallpaperManager = WallpaperManager.getInstance(getContext());
		initAnimation();
		setAnimationCacheEnabled(false);

		this.mAdapter = new ApplicationsAdapter(this.mContext,
				this.mAllAppsList);
		this.mDataSetObserver = new AdapterDataSetObserver();
		this.mAdapter.registerDataSetObserver(this.mDataSetObserver);
		this.mAdapter.setNotifyOnChange(false);
		this.setBackgroundColor(Color.parseColor("#80000000"));

	}

	private void initAnimation() {
		int i = 0;
		int j = this.mItemNumOfPage;

		while (i < j) {
			if (Launcher.USE_MAINMENU_CONCENTRATION_EFFECT) {
				float f1 = getXDeltaValue(i);
				float f2 = getYDeltaValue(i);
				TranslateAnimation localTranslateAnimation1 = new TranslateAnimation(
						f1, 0.0F, f2, 0.0F);
				OvershootInterpolator localOvershootInterpolator = new OvershootInterpolator(
						1.0F);
				localTranslateAnimation1
						.setInterpolator(localOvershootInterpolator);

				AlphaAnimation localAlphaAnimation1 = new AlphaAnimation(0.0F,
						1.0F);
				Interpolator localInterpolator = this.mOpenAlphaAnimationInterpolator;
				localAlphaAnimation1.setInterpolator(localInterpolator);

				AnimationSet localAnimationSet1 = new AnimationSet(false);
				localAnimationSet1.addAnimation(localTranslateAnimation1);
				localAnimationSet1.addAnimation(localAlphaAnimation1);
				this.mOpenAnimations[i] = localAnimationSet1;

				AnimationSet localAnimationSet2 = new AnimationSet(true);
				TranslateAnimation localTranslateAnimation2 = new TranslateAnimation(
						0.0F, f1, 0.0F, f2);
				localAnimationSet2.addAnimation(localTranslateAnimation2);

				AlphaAnimation localAlphaAnimation2 = new AlphaAnimation(1.0F,
						1.0F);
				localAnimationSet2.addAnimation(localAlphaAnimation2);
				this.mCloseAnimations[i] = localAnimationSet2;

				Animation localAnimation1 = this.mCloseAnimations[i];
				AnticipateInterpolator localAnticipateInterpolator = new AnticipateInterpolator(
						1.0F);
				localAnimation1.setInterpolator(localAnticipateInterpolator);
			} else {
				Animation[] arrayOfAnimation1 = this.mOpenAnimations;
				TranslateAnimation localTranslateAnimation3 = new TranslateAnimation(
						0.0F, 0.0F, 0.0F, 0.0F);
				arrayOfAnimation1[i] = localTranslateAnimation3;

				Animation[] arrayOfAnimation2 = this.mCloseAnimations;
				TranslateAnimation localTranslateAnimation4 = new TranslateAnimation(
						0.0F, 0.0F, 0.0F, 0.0F);
				arrayOfAnimation2[i] = localTranslateAnimation4;

				Animation localAnimation2 = this.mOpenAnimations[i];
				LinearInterpolator localLinearInterpolator1 = new LinearInterpolator();
				localAnimation2.setInterpolator(localLinearInterpolator1);

				Animation localAnimation3 = this.mCloseAnimations[i];
				LinearInterpolator localLinearInterpolator2 = new LinearInterpolator();
				localAnimation3.setInterpolator(localLinearInterpolator2);
			}

			i++;
		}

		this.mMenuOpenAni.setDelay(0.0F);
		this.mMenuCloseAni.setDelay(0.0F);
	}

	private void initPageIndicator() {
		// LogUtils.d(PageIndicator.TAG, "initPageIndicator");
		int i = 0;

		if (this.mPageIndicator == null) {
			this.mPageIndicator = new PageIndicator();
		}

		int j = getChildCount();

		if (j > 9) {
			j = 9;
		}

		int k = this.mPageIndicatorLarge.getIntrinsicWidth();
		this.mPageIndicator.setPageDrawable(mPageIndicatorLarge);
		this.mPageIndicator.setMoreDrawable(mPageIndicatorMore);
		mPageIndicator.setPageCount(j);
		mPageIndicator.setGap(this.mPageIndicatorGap);
		mPageIndicator.setTextSize(this.mTextSize);
		this.mPageIndicatorTop = getResources().getDimensionPixelSize(
				R.dimen.workspace_pageindicator_top);

		if (this.mEnablePageIndicatorShowHide) {
			mPageIndicator.enableShowHide(true);

			int i1 = k * j;
			int i2 = this.mPageIndicatorGap;

			if (j > 0) {
				i = j - 1;
			}

			int i3 = i2 * i;
			int i4 = i1 + i3;
			int i5 = (getWidth() - i4) / 2;
			this.mPageIndicatorLeft = i5;
		} else {
			mPageIndicator.enableShowHide(false);
		}
	}

	/**
	 * 完整 .
	 * 
	 * @return
	 */
	private boolean isListChild() {
		if (getChildCount() == 1) {
			View localView = getChildAt(0);

			if ((localView != null) && localView instanceof ListView) {
				return true;
			}
		}

		return false;
	}

	/**
	 * 在主菜单上增加一屏.
	 * 
	 * @return
	 */
	private AppMenu makeMenuView() {
		AppMenu localAppMenu = new AppMenu(getContext(), this.mOrientation);
		addView(localAppMenu, new ViewGroup.LayoutParams(
				ViewGroup.LayoutParams.FILL_PARENT,
				ViewGroup.LayoutParams.FILL_PARENT));

		if (this.mMode == EDIT_MODE) {
			localAppMenu.setBitmap(this.mDeleteIcon);
			localAppMenu.setEditBg(this.mEditMenuBg);
			localAppMenu.setEnabledChildAnimation(true);
		} else {
			localAppMenu.setBitmap(null);
			localAppMenu.setEditBg(null);
			localAppMenu.setEnabledChildAnimation(false);
		}

		return localAppMenu;
	}

	private void snapToDestination() {
		int i = getWhichScreen();
		// Log.e(TAG,"snapToDestination "+i);
		snapToScreen(i);
	}

	private void snapToScreen(int whichScreen, final int duration) {
		if (isListChild()) {
			return;
		}

		int i = this.mCurrentScreen - 1;
		int j = this.mCurrentScreen + 1;
		enableChildrenCache(i, j);
		// if (this.mPageIndicator != null) {
		// this.mPageIndicator.show();
		// }
		whichScreen = Math.max(0, Math.min(whichScreen, getChildCount() - 1));

		boolean changingScreens = whichScreen != mCurrentScreen;
		mNextScreen = whichScreen;

		View focusedChild = getFocusedChild();

		if ((focusedChild != null) && changingScreens
				&& (focusedChild == getChildAt(mCurrentScreen))) {
			focusedChild.clearFocus();
		}

		final int newX = whichScreen * getWidth();
		final int delta = newX - mScrollX;
		mScroller.startScroll(mScrollX, 0, delta, 0, duration);
		invalidate();

		// Log.e(TAG, "	mScroller.startScroll  deltaX" + delta);
	}

	private void updateMenu() {

		LogUtils.d(TAG, "updateMenu-start");

		// Log.e(TAG, "updateMenu-start");

		// DatabaseUtils.dumpCursor(com.android.launcher3.LauncherModel.loadAppFromDatabase(this.mContext));

		// Log.e(TAG,"mItemNumOfPage "+this.mItemNumOfPage);

		if (this.mAdapter == null) {
			return;
		}

		ApplicationInfo localApplicationInfo1;

		int adapterCount = this.mAdapter.getCount();
		AppShortcutZone localAppShortcutZone1 = this.mLauncher
				.getAppShortcutZone();
		removeAllViews();

		if (this.mMode == EDIT_MODE) {
			localAppShortcutZone1.setBitmap(this.mDeleteIcon);
			localAppShortcutZone1.setEditBg(this.mEditTopBg);
			localAppShortcutZone1.setEnabledChildAnimation(true);
			localAppShortcutZone1.changeApplicationsIcon();
			localAppShortcutZone1.invalidate();
		} else {
			localAppShortcutZone1.setBitmap(null);
			localAppShortcutZone1.setEditBg(null);
			localAppShortcutZone1.setEnabledChildAnimation(false);
			localAppShortcutZone1.invalidate();
		}

		// localAppShortcutZone1.loadApplications();

		ArrayList<ApplicationInfo> topAppList = new ArrayList<ApplicationInfo>();
		ArrayList<ApplicationInfo> menuList = new ArrayList<ApplicationInfo>();

		if (adapterCount > 0) {
			for (int i = 0; i < adapterCount; i++) {
				localApplicationInfo1 = (ApplicationInfo) this.mAdapter
						.getItem(i);

				if (localApplicationInfo1.topNum != -1) {
					topAppList.add(localApplicationInfo1);
				} else {
					menuList.add(localApplicationInfo1);
				}
			}

			// if (this.mMode == LAUNCH_MODE_LIST) {
			// this.createListView(mAdapter);

			// int topAppCount = topAppList.size();
			//
			// for (int i = 0; i < topAppCount; i++) {
			// ApplicationInfo localApplicationInfo3 = (ApplicationInfo)
			// topAppList
			// .get(i);
			// localAppShortcutZone1.updateApplication(localApplicationInfo3,
			// localApplicationInfo3.topNum);
			// }

			// return;
			// }

			// topAppList.clear();
		}

		localAppShortcutZone1.clearApplications();

		// long start=System.currentTimeMillis();
		//
		int i10 = topAppList.size();

		for (int i = 0; i < i10; i++) {
			ApplicationInfo localApplicationInfo = (ApplicationInfo) topAppList
					.get(i);
			int i66 = localApplicationInfo.editTopNum;
			localAppShortcutZone1.updateApplication(localApplicationInfo, i66);
		}

		// Log.e(TAG, "update    AppShortcutZone1 ");
		//
		// Log.e(TAG,"update    AppShortcutZone1   took  "+(
		// System.currentTimeMillis()-start)+"ms");

		topAppList.clear();

		if (this.mMode == LAUNCH_MODE_LIST) {
			this.createListView(mAdapter);
			return;
		}

		this.mAdapter.setNotifyOnChange(false);

		this.mOrderComparator.setMode(this.mMode);
		this.mAdapter.sort(this.mOrderComparator);

		//

		// Log.e(TAG,"After  sort ###########################");
		// this.printApplicationsAdapter();
		// Log.e(TAG," ###########################");
		int c = mAllAppsList.size();
		int i = 0;

		// 倒序操作
		if (mAllAppsList != null && mAllAppsList.size() > 0) {
			while (mAllAppsList.get(0).pageNum < 0 && i < c) {
				mAllAppsList.add(mAllAppsList.remove(0));
				i++;
			}
		}

		// Log.e(TAG,"after change   "+ mAllAppsList.toString());

		// this.printApplicationsAdapter();
		int i3 = 0;

		while (i3 < adapterCount) {

			localApplicationInfo1 = (ApplicationInfo) this.mAdapter.getItem(i3);

			if (localApplicationInfo1.editTopNum != -1) {
				// topAppList.add(localApplicationInfo1);
				i3++;
				continue;
			}

			AppMenu localAppMenu1;

			if (localApplicationInfo1.editPageNum == -1) {
				localAppMenu1 = this.getEmptyPageView(0);
				localApplicationInfo1.editPageNum = this.mTempPage;
				localApplicationInfo1.editCellNum = localAppMenu1
						.getChildCount();
			} else {
				// Log.e(TAG,"getEmptyPageView "+localApplicationInfo1.editPageNum);
				localAppMenu1 = this
						.getEmptyPageView(localApplicationInfo1.editPageNum);
				localApplicationInfo1.editPageNum = this.mTempPage;
				localApplicationInfo1.editCellNum = localAppMenu1
						.getChildCount();
			}

			View localView1 = this.makeItemView(i3, localAppMenu1);
			localView1.setTag(localApplicationInfo1);

			localAppMenu1.addView(localView1);

			if (localApplicationInfo1.cellNum != (localAppMenu1.getChildCount() - 1)) {
				localApplicationInfo1.editCellNum = localAppMenu1
						.getChildCount() - 1;
			}

			localApplicationInfo1.topNum = localApplicationInfo1.editTopNum;
			localApplicationInfo1.pageNum = localApplicationInfo1.editPageNum;
			localApplicationInfo1.cellNum = localApplicationInfo1.editCellNum;

			i3++;
		}

		// 如果是编辑状态，则增加一个空白屏幕.
		if (this.mMode == EDIT_MODE) {
			makeMenuView();
		}

		// 对 AppShortcutZone 进行更新.

		// localAppShortcutZone1.clearApplications();
		//
		//
		//
		// int i10 = topAppList.size();
		//
		// for(i=0;i<i10;i++)
		// {
		// ApplicationInfo localApplicationInfo = (ApplicationInfo) topAppList
		// .get(i);
		// if (this.mMode == EDIT_MODE) {
		// int i66 = localApplicationInfo.editTopNum;
		// localAppShortcutZone1.updateApplication(localApplicationInfo,
		// i66);
		// } else {
		// int i68 = localApplicationInfo.topNum;
		// localAppShortcutZone1.updateApplication(localApplicationInfo,
		// i68);
		// }
		//
		// }
		//
		// topAppList.clear();

		// 以下到结束是对 mCurrentScreen 进行校正.

		// int i70 = getChildCount();
		// if (i70 > 0) {
		// int i71 = this.mCurrentScreen;
		// if (i71 >= i70) {
		// this.mCurrentScreen = i70 - 1;
		// int i76 = this.mCurrentScreen * getWidth();
		// this.scrollTo(i76, 0);
		// }
		// } else {
		// this.mCurrentScreen = 0;
		// this.scrollTo(0, 0);
		// }

		LogUtils.d(TAG, "updateMenu-end");
	}

	/**
	 * 完整
	 * 
	 */
	abstract interface InterruptableAnimationListener extends
			Animation.AnimationListener {
		public abstract void interrupt();
	}

	/**
	 * 完整
	 */
	class AdapterDataSetObserver extends DataSetObserver {
		/**
		 * Creates a new AdapterDataSetObserver object.
		 */
		AdapterDataSetObserver() {
			// Log.d("Launcher", "AdapterDataSetObserver");
		}

		public void onChanged() {
			// Log.e(TAG, "AdapterDataSetObserver  onChanged");
			// Log.e(TAG, " before updateMenu");
			// printApplicationsAdapter();
			MenuManager.this.updateMenu();

			// Log.e(TAG, "after updateMenu");
			// printApplicationsAdapter();
			// Log.e(TAG,"AdapterDataSetObserver  onChanged ###########################");

			// 根据localApplicationInfo.isUpdated这个标志来决定是否更新到数据库
			// 如果这个值为false的话，则说明应该更新.
			if (MenuManager.this.mMode != EDIT_MODE) {
				stopUpdateDB();
				startUpdateDB();
			}
		}

		public void onInvalidated() {
			Log.d("Launcher", "AdapterDataSetObserver-onInvalidated");
			MenuManager.this.updateMenu();
		}
	}

	class AppMenuOnClickListener implements View.OnClickListener {
		public void onClick(final View v) {
			LogUtils.d(TAG, "AppMenuOnClickListener-onClick");

			Object localObject = v.getTag();

			if ((localObject != null)
					&& (localObject instanceof ApplicationInfo)) {
				ApplicationInfo localApplicationInfo = (ApplicationInfo) localObject;

				if (MenuManager.this.mMode == EDIT_MODE) {
					if (!localApplicationInfo.systemApp) {
						String str = localApplicationInfo.intent.getComponent()
								.getPackageName();
						MenuManager.this.mLauncher.showDeleteApplication(str);

						return;
					}
				} else {
					Log.d("Launcher", "AppMenuOnClickListener-intent"
							+ localApplicationInfo.intent);
					mLauncher.startActivitySafely(localApplicationInfo.intent);
				}
			}
		}
	}

	class AppMenuOnLongClickListener implements View.OnLongClickListener {
		public boolean onLongClick(final View v) {
			LogUtils.v(TAG, "AppMenuOnLongClickListener-onLongClick");

			Object localObject = v.getTag();

			if ((localObject != null)
					&& (localObject instanceof ApplicationInfo)) {
				if (mMode == EDIT_MODE) {
					int dropScreen = getDropScreen();
					AppMenu localAppMenu = (AppMenu) MenuManager.this
							.getChildAt(dropScreen);
					int appCount = localAppMenu.getChildCount();

					for (int i = 0; i < appCount; i++) {
						if (localAppMenu.getChildAt(i) == v) {
							mDragView = v;
							mDragCell = i;

							break;
						}
					}

					ApplicationInfo localApplicationInfo = (ApplicationInfo) localObject;
					mDragger.startDrag(v, MenuManager.this,
							localApplicationInfo,
							DragController.DRAG_ACTION_MOVE);
				} else {
					ApplicationInfo localApplicationInfo = (ApplicationInfo) localObject;
					mDragger.startDrag(v, MenuManager.this,
							localApplicationInfo,
							DragController.DRAG_ACTION_MOVE);
					close();
				}
			}

			return true;
		}
	}

	class ListViewOnItemClickListener implements
			AdapterView.OnItemClickListener {
		public void onItemClick(final AdapterView<?> paramAdapterView,
				final View paramView, final int paramInt, final long paramLong) {
			ApplicationInfo localApplicationInfo = (ApplicationInfo) paramAdapterView
					.getAdapter().getItem(paramInt);
			Intent localIntent = localApplicationInfo.intent;
			mLauncher.startActivitySafely(localIntent, null);
		}
	}

	class ListViewOnItemLongClickListener implements
			AdapterView.OnItemLongClickListener {
		public boolean onItemLongClick(final AdapterView<?> paramAdapterView,
				final View paramView, final int paramInt, final long paramLong) {
			ApplicationInfo localApplicationInfo = (ApplicationInfo) paramAdapterView
					.getAdapter().getItem(paramInt);
			mDragger.startDrag(paramView, MenuManager.this,
					localApplicationInfo,
					DragController.DRAG_ACTION_COPY_AND_ICON_CENTER);
			close();

			return true;
		}
	}

	class MenuCloseAnimationController extends LayoutAnimationController {
		/**
		 * Creates a new MenuCloseAnimationController object.
		 */
		public MenuCloseAnimationController(final Context context) {
			super(context, null);
		}

		protected long getDelayForView(final View v) {
			LayoutAnimationController.AnimationParameters localAnimationParameters = v
					.getLayoutParams().layoutAnimationParameters;
			this.mAnimation = MenuManager.this.mCloseAnimations[localAnimationParameters.index];
			this.mAnimation.setDuration(ANIMATION_OUT_TIME);
			return super.getDelayForView(v);
		}
	}

	class MenuOpenAnimationController extends LayoutAnimationController {
		/**
		 * Creates a new MenuOpenAnimationController object.
		 */
		public MenuOpenAnimationController(final Context context) {
			super(context, null);
		}

		protected long getDelayForView(final View v) {
			LayoutAnimationController.AnimationParameters localAnimationParameters = v
					.getLayoutParams().layoutAnimationParameters;
			this.mAnimation = MenuManager.this.mOpenAnimations[localAnimationParameters.index];
			this.mAnimation.setDuration(ANIMATION_IN_TIME);

			return super.getDelayForView(v);
		}
	}

	class UpdateDBTask extends AsyncTask<ApplicationsAdapter, Void, Void> {
		/**
		 * Creates a new UpdateDBTask object.
		 */
		private UpdateDBTask() {
		}

		protected Void doInBackground(final ApplicationsAdapter[] adapters) {
			// Log.e("Launcher", "UpdateDBTask-doInBackground");
			if (adapters == null) {
				return null;
			}

			ApplicationsAdapter localApplicationsAdapter = adapters[0];

			if (localApplicationsAdapter == null) {
				return null;
			}

			int count = localApplicationsAdapter.getCount();

			for (int i = 0; i < count; i++) {
				if (isCancelled()) {
					return null;
				}

				ApplicationInfo localApplicationInfo = localApplicationsAdapter
						.getItem(i);

				if ((localApplicationInfo != null)
						&& !localApplicationInfo.isUpdated) {
					// Log.e(TAG, "UpdateDBTask-doInBackground  " + i);
					// Log.e(TAG,
					// "topNum=" + localApplicationInfo.topNum + ",pageNum="
					// + localApplicationInfo.pageNum + ",cellNum="
					// + localApplicationInfo.cellNum + ",title="
					// +
					// localApplicationInfo.title+" componentName =   "+localApplicationInfo.componentName.toShortString()
					// );
					LauncherModel.updateAppToDatabase(
							MenuManager.this.mContext, localApplicationInfo);
				}
			}

			return null;
		}
	}
}
